
#include "home_page.h"
#include "page_base.h"
#include "img_common.h"
#include "sys_scene.h"
#include "pt_ipc.h"
#include "pt_info.h"
#include "pt_dev.h"
#include "sys_font.h"
#include "pt_fs.h"
#include "pt_btnsetting.h"

static int * info_ball[2] =
{
    &infoball_00,&InfoballShutdown 
 };

static ui_widget_home_t home_widget;

void ui_init_home_page_src(lv_obj_t *superview)
{
    debug_d("home page create\n");

    home_widget.dev_num = pt_dev_num_get();

    // 公共部分
    ui_home_page_common(superview);
    ui_home_page_btn_img_create(superview);

    // 时间和温度
    if((0 == home_widget.dev_num) || (1 == home_widget.dev_num))
    {
        ui_home_page_time_big(superview);
    }
    else
    {

    }


    // 信息球
    if(1 == home_widget.dev_num){
        ui_home_page_one_dev(superview);
    }
    else if(2 == home_widget.dev_num){
        ui_home_page_two_dev(superview);
    }
    else if(3 <= home_widget.dev_num){
        ui_home_page_three_dev(superview);
    }

    debug_d("end\n");
}

void ui_release_home_page_src(lv_obj_t *superview)
{
    home_widget.dev_num = 0;

    if(home_widget.label_bottom_left){
        lv_obj_del(home_widget.label_bottom_left);
        home_widget.label_bottom_left = NULL;
    }
    if(home_widget.label_bottom_mid){
        lv_obj_del(home_widget.label_bottom_mid);
        home_widget.label_bottom_mid = NULL;
    }
    if(home_widget.label_bottom_right){
        lv_obj_del(home_widget.label_bottom_right);
        home_widget.label_bottom_right = NULL;
    }
    if(home_widget.bg_img){
        lv_obj_del(home_widget.bg_img);
        home_widget.bg_img = NULL;
    }

    if(home_widget.label_title){
        lv_obj_del(home_widget.label_title);
        home_widget.label_title = NULL;
    }

    if(home_widget.label_hour){
        lv_obj_del(home_widget.label_hour);
        home_widget.label_hour = NULL;
    }

    if(home_widget.label_colon){
        lv_obj_del(home_widget.label_colon);
        home_widget.label_colon = NULL;
    }
    
    if(home_widget.label_min){
        lv_obj_del(home_widget.label_min);
        home_widget.label_min = NULL;
    }

    if(home_widget.label_date){
        lv_obj_del(home_widget.label_date);
        home_widget.label_date = NULL;
    }

    if(home_widget.label_outside_tempera){
        lv_obj_del(home_widget.label_outside_tempera);
        home_widget.label_outside_tempera = NULL;
    }

    if(home_widget.timer_home_refresh){
        lv_timer_del(home_widget.timer_home_refresh);
        home_widget.timer_home_refresh = NULL;
    }

    if(home_widget.img_ball1){
        lv_obj_del(home_widget.img_ball1);
        home_widget.img_ball1 = NULL;
    }

    if(home_widget.img_ball2){
        lv_obj_del(home_widget.img_ball2);
        home_widget.img_ball2 = NULL;
    }

    if(home_widget.img_ball3){
        lv_obj_del(home_widget.img_ball3);
        home_widget.img_ball3 = NULL;
    }

    if(home_widget.label_electric_heater_title){
        home_widget.label_electric_heater_title = NULL;
    }

    if(home_widget.label_electric_heater_val){
        home_widget.label_electric_heater_val = NULL;
    }

    if(home_widget.label_gas_heater_title){
        home_widget.label_gas_heater_title = NULL;
    }

    if(home_widget.label_gas_heater_val){
        home_widget.label_gas_heater_val = NULL;
    }

    if(home_widget.label_water_salt_title){
        home_widget.label_water_salt_title = NULL;
    }

    if(home_widget.label_water_salt_val){
        home_widget.label_water_salt_val = NULL;
    }

    if(home_widget.label_water_TDS_title){
        home_widget.label_water_TDS_title = NULL;
    }

    if(home_widget.label_water_TDS_val){
        home_widget.label_water_TDS_val = NULL;
    }

    if(home_widget.btn_timer){
        lv_timer_del(home_widget.btn_timer);
        home_widget.btn_timer = NULL;
    }
    if(home_widget.btn_left_img){
        lv_obj_del(home_widget.btn_left_img);
        home_widget.btn_left_img = NULL;
    }
    if(home_widget.btn_mid_img){
        lv_obj_del(home_widget.btn_mid_img);
        home_widget.btn_mid_img = NULL;
    }
    if(home_widget.btn_right_img){
        lv_obj_del(home_widget.btn_right_img);
        home_widget.btn_right_img = NULL;
    }  
}

static void home_page_on_view_did_load(page_base_t* self)
{
    debug_d("home create\n");
    ui_init_home_page_src(self->root);
}
static void home_page_on_custom_attr_config(page_base_t* self)
{
    //debug_d("priv.state   =%d\n",self->priv.state);
    //debug_d("priv.is_enter=%d\n",self->priv.anim.is_enter);
    //debug_d("priv.is_busy =%d\n",self->priv.anim.is_busy);
}
static void home_page_on_base_view_load(page_base_t* self)
{

}
static void home_page_on_base_view_will_appear(page_base_t* self)
{

}
static void home_page_on_base_view_did_appear(page_base_t* self)
{

}
static void home_page_on_base_view_will_disappear(page_base_t* self)
{

}
static void home_page_on_base_view_did_disappear(page_base_t* self)
{

}
static void home_page_on_view_did_unload(page_base_t* self)
{
    debug_d("home end\n");
    ui_release_home_page_src(self->root);
}

static page_vtable_t page_param = {
    .on_custom_attr_config  = home_page_on_custom_attr_config,
    .on_view_load           = home_page_on_base_view_load,
    .on_view_did_load       = home_page_on_view_did_load,
    .on_view_will_appear    = home_page_on_base_view_will_appear,
    .on_view_did_appear     = home_page_on_base_view_did_appear,
    .on_view_will_disappear = home_page_on_base_view_will_disappear,
    .on_view_did_disappear  = home_page_on_base_view_did_disappear,
    .on_view_did_unload     = home_page_on_view_did_unload,
};

page_vtable_t* lv_page_home_create(void)
{
    return &page_param;
}

int ui_home_update_btnname(void)
{
    if(home_widget.label_bottom_left){
        lv_label_set_text(home_widget.label_bottom_left,btn_left_get_buttonName());
    }

     if(home_widget.label_bottom_mid){
        lv_label_set_text(home_widget.label_bottom_mid,btn_middle_get_buttonName());
    }   

    if(home_widget.label_bottom_right){
        lv_label_set_text(home_widget.label_bottom_right,btn_right_get_buttonName());
    }

    return 0;
}

void ui_home_page_common(lv_obj_t *superview)
{
 
    int cap = 0;
    int len = 0;
    lv_coord_t pw = 0;
    lv_coord_t ph = 0;

    pw = lv_disp_get_hor_res(NULL);
    ph = lv_disp_get_ver_res(NULL);

    cap = 110;
    len = (pw - cap*3)/4;
    //****************************************************** */
    home_widget.bg_img = lv_img_create(superview);
    #if 0
    lv_img_set_src(home_widget.bg_img,pt_fs_get("BG_Home.png"));
    #else
    lv_img_set_src(home_widget.bg_img,&BG_Home);
    #endif
    lv_obj_set_pos(home_widget.bg_img,0,0);
    lv_img_t* img = NULL;
	img = (lv_img_t*)home_widget.bg_img;

    debug_d("bg w:h=%d:%d\n",img->w,img->h);
    //*****************************************************/
    home_widget.label_bottom_left = lv_label_create(superview);
    lv_obj_set_style_text_font(home_widget.label_bottom_left, lv_font_get(20), LV_STATE_DEFAULT );//字体大小
    lv_obj_set_style_text_color(home_widget.label_bottom_left, lv_color_make(0xff,0xff,0xff), LV_PART_MAIN);
    lv_obj_set_style_text_align(home_widget.label_bottom_left,LV_TEXT_ALIGN_CENTER,0);

    lv_label_set_text(home_widget.label_bottom_left,btn_left_get_buttonName());
    lv_obj_set_pos(home_widget.label_bottom_left,len*1+cap*0-20,290);
    lv_obj_set_size(home_widget.label_bottom_left,cap,24);  
    lv_label_set_long_mode(home_widget.label_bottom_left,LV_LABEL_LONG_DOT);

#if 1
	lv_obj_set_style_bg_opa(home_widget.label_bottom_left, LV_OPA_0, LV_PART_MAIN);
#else
	lv_obj_set_style_bg_opa(home_widget.label_bottom_left, LV_OPA_100, LV_PART_MAIN);
	lv_obj_set_style_bg_color(home_widget.label_bottom_left, lv_color_make(0xFF, 0, 0), LV_PART_MAIN);
#endif
    //*****************************************************/
    home_widget.label_bottom_mid = lv_label_create(superview);
    lv_obj_set_style_text_font(home_widget.label_bottom_mid, lv_font_get(20), LV_STATE_DEFAULT );//字体大小
    lv_obj_set_style_text_color(home_widget.label_bottom_mid, lv_color_make(0xff,0xff,0xff), LV_PART_MAIN);
    lv_obj_set_style_text_align(home_widget.label_bottom_mid,LV_TEXT_ALIGN_CENTER,0);
    lv_label_set_text(home_widget.label_bottom_mid,btn_middle_get_buttonName());
    lv_obj_set_pos(home_widget.label_bottom_mid,len*2+cap*1-15,290);
    lv_obj_set_size(home_widget.label_bottom_mid,cap,24); 
    lv_label_set_long_mode(home_widget.label_bottom_mid,LV_LABEL_LONG_DOT); 

#if 1
	lv_obj_set_style_bg_opa(home_widget.label_bottom_mid, LV_OPA_0, LV_PART_MAIN);
#else
	lv_obj_set_style_bg_opa(home_widget.label_bottom_mid, LV_OPA_100, LV_PART_MAIN);
	lv_obj_set_style_bg_color(home_widget.label_bottom_mid, lv_color_make(0xFF, 0, 0), LV_PART_MAIN);
#endif

    //*****************************************************/
    home_widget.label_bottom_right = lv_label_create(superview);
    lv_obj_set_style_text_font( home_widget.label_bottom_right, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_bottom_right, lv_color_make(0xff,0xff,0xff), LV_PART_MAIN);
    lv_obj_set_style_text_align(home_widget.label_bottom_right,LV_TEXT_ALIGN_CENTER,0);
    lv_label_set_text(home_widget.label_bottom_right,btn_right_get_buttonName());
    lv_obj_set_pos(home_widget.label_bottom_right,len*3+cap*2-15,290);
    lv_obj_set_size(home_widget.label_bottom_right,cap,24); 
    lv_label_set_long_mode(home_widget.label_bottom_right,LV_LABEL_LONG_DOT);
     
#if 1
	lv_obj_set_style_bg_opa(home_widget.label_bottom_right, LV_OPA_0, LV_PART_MAIN);
#else
	lv_obj_set_style_bg_opa(home_widget.label_bottom_right, LV_OPA_100, LV_PART_MAIN);
	lv_obj_set_style_bg_color(home_widget.label_bottom_right, lv_color_make(0xFF, 0, 0), LV_PART_MAIN);
#endif
    //*****************************************************/
}

void home_page_btn_time_callback(lv_timer_t * timer)
{
    ui_home_page_btn_update();
}

void ui_home_page_btn_img_create(lv_obj_t *superview)
{
    lv_coord_t pw = 0;
    lv_coord_t ph = 0;

    pw = lv_disp_get_hor_res(NULL);
    ph = lv_disp_get_ver_res(NULL);
    // lv_obj_t * btn_left_img;
    // lv_obj_t * btn_mid_img;
    // lv_obj_t * btn_right_img;

    home_widget.btn_left_img = lv_img_create(superview);
    lv_img_set_src(home_widget.btn_left_img,pt_fs_get("SelectedBlue.png"));//109x14
    lv_obj_set_pos(home_widget.btn_left_img,20,ph - 14);
    lv_obj_set_size(home_widget.btn_left_img,109,14);

    home_widget.btn_mid_img = lv_img_create(superview);
    lv_img_set_src(home_widget.btn_mid_img,pt_fs_get("SelectedBlue.png"));//109x14
    lv_obj_set_pos(home_widget.btn_mid_img,170,ph - 14);
    lv_obj_set_size(home_widget.btn_mid_img,109,14);

    home_widget.btn_right_img = lv_img_create(superview);
    lv_img_set_src(home_widget.btn_right_img,pt_fs_get("SelectedBlue.png"));//109x14
    lv_obj_set_pos(home_widget.btn_right_img,320,ph - 14);
    lv_obj_set_size(home_widget.btn_right_img,109,14);

    ui_home_page_btn_update();

    home_widget.btn_timer = lv_timer_create(home_page_btn_time_callback,2000,NULL);
}

void ui_home_page_btn_update(void)
{
#if 0
    if(!btn_left_is_radio())
    {
        if(relay_read_status(POROS_RELAY1))
        {
            lv_obj_clear_flag(home_widget.btn_left_img,LV_OBJ_FLAG_HIDDEN);
        }else{
            lv_obj_add_flag(home_widget.btn_left_img,LV_OBJ_FLAG_HIDDEN);
        }
    }
    else{
        lv_obj_add_flag(home_widget.btn_left_img,LV_OBJ_FLAG_HIDDEN);
    }

    if(!btn_middle_is_radio())
    {
        if(relay_read_status(POROS_RELAY2))
        {
            lv_obj_clear_flag(home_widget.btn_mid_img,LV_OBJ_FLAG_HIDDEN);
        }else{
            lv_obj_add_flag(home_widget.btn_mid_img,LV_OBJ_FLAG_HIDDEN);
        }
    }
    else{
        lv_obj_add_flag(home_widget.btn_mid_img,LV_OBJ_FLAG_HIDDEN);
    }

    if(!btn_right_is_radio())
    {
        if(relay_read_status(POROS_RELAY3))
        {
            lv_obj_clear_flag(home_widget.btn_right_img,LV_OBJ_FLAG_HIDDEN);
        }else{
            lv_obj_add_flag(home_widget.btn_right_img,LV_OBJ_FLAG_HIDDEN);
        }
    }
    else{
        lv_obj_add_flag(home_widget.btn_right_img,LV_OBJ_FLAG_HIDDEN);
    } 
#endif
}





void ui_home_page_time_big(lv_obj_t *superview)
{
    get_sys_date();

    home_widget.label_hour = lv_label_create(superview);
    lv_obj_set_style_text_font(home_widget.label_hour, lv_font_get(80), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_hour,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_hour,LV_OPA_90,0);
    lv_label_set_text_fmt( home_widget.label_hour, "%02d", pt_hour_get());
    lv_obj_set_pos(home_widget.label_hour,25,70);

    home_widget.label_colon = lv_label_create(superview);
    lv_obj_set_style_text_font(home_widget.label_colon, lv_font_get(80), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_colon,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_colon,LV_OPA_90,0);
    lv_label_set_text_fmt( home_widget.label_colon, ":");
    lv_obj_set_pos(home_widget.label_colon,120,70);

    home_widget.label_min = lv_label_create(superview);
    lv_obj_set_style_text_font(home_widget.label_min, lv_font_get(80), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_min,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_min,LV_OPA_90,0);
    lv_label_set_text_fmt( home_widget.label_min, "%02d", pt_minute_get());
    lv_obj_set_pos(home_widget.label_min,145,70);

    home_widget.label_outside_tempera = lv_label_create(superview);
    lv_obj_set_style_text_font(home_widget.label_outside_tempera, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_outside_tempera,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_outside_tempera,LV_OPA_70,0);
    lv_label_set_text_fmt( home_widget.label_outside_tempera, "室外%d°C", pt_temperature_get());
    lv_obj_set_pos(home_widget.label_outside_tempera,150,170);

    debug_d("month=%d\n",pt_month_get());
    debug_d("day=%d\n",pt_day_get());
    debug_d("week=%d\n",pt_week_get());
    debug_d("week2=%s\n", pt_week_txt_get(pt_week_get()));

    home_widget.label_date = lv_label_create(superview);
    lv_obj_set_style_text_font(home_widget.label_date, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_date,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_date,LV_OPA_70,0);
    lv_label_set_text_fmt( home_widget.label_date, "%02d/%02d %s", pt_month_get(),pt_day_get(), pt_week_txt_get(pt_week_get()));
    lv_obj_set_pos(home_widget.label_date,27,170);


    home_widget.timer_home_refresh = lv_timer_create(timer_home_refresh_cb, 1000,NULL);
}

void timer_home_refresh_cb(lv_timer_t * timer)
{
    static bool two_val = 0;
    static int sec = 0;
    if(sec != pt_sec_get())
    {
        two_val = !two_val;
        if(two_val)
            lv_label_set_text_fmt(home_widget.label_colon, ":");
        else
            lv_label_set_text_fmt(home_widget.label_colon, " ");
    }

    static int min = 0;
    if(min != pt_minute_get())
    {
        lv_label_set_text_fmt(home_widget.label_hour, "%02d", pt_hour_get());
        lv_label_set_text_fmt(home_widget.label_min, "%02d", pt_minute_get());
        min = pt_minute_get();
    }

    static int day = 0;
    if(day != pt_day_get())
    {
        lv_label_set_text_fmt( home_widget.label_date, "%02d/%02d %s", pt_month_get(),pt_day_get(), pt_week_txt_get(pt_week_get()));
        day = pt_day_get();
    }

    static int temper = 0;
    if(temper != pt_temperature_get())
    {
        lv_label_set_text_fmt( home_widget.label_outside_tempera, "室外%d°C", pt_temperature_get());
        temper = pt_temperature_get();
    }

    if(btn_get_update_flag())
    {
        btn_set_update_flag(0);
        ui_home_update_btnname();
    }
}

void ui_home_page_one_dev(lv_obj_t *superview)
{
    home_widget.img_ball1 = lv_img_create(superview);
    lv_img_set_src( home_widget.img_ball1, info_ball[0]);
    lv_obj_set_pos(home_widget.img_ball1,260,35);

    home_widget.label_electric_heater_val = lv_label_create(home_widget.img_ball1);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_val, lv_font_get(60), LV_STATE_DEFAULT );;
    lv_obj_set_style_text_color(home_widget.label_electric_heater_val,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_val,LV_OPA_90,0);
    lv_label_set_text(home_widget.label_electric_heater_val, "50");
    lv_obj_align(home_widget.label_electric_heater_val,LV_ALIGN_CENTER,0,-15);

    home_widget.label_electric_heater_title = lv_label_create(home_widget.img_ball1);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_title, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_title,lv_color_make(0xff,0xff,0xff),0);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_title,LV_OPA_70,0);
    lv_label_set_text(home_widget.label_electric_heater_title, "电热 | °C");
    lv_obj_align(home_widget.label_electric_heater_title,LV_ALIGN_CENTER,0,30);
}

void ui_home_page_two_dev(lv_obj_t *superview)
{
    // info_ball 1 ***********************************************************************************************************

    home_widget.img_ball1 = lv_img_create(superview);
    lv_img_set_src( home_widget.img_ball1, info_ball[0]);
    lv_obj_set_pos(home_widget.img_ball1,28,23);

    home_widget.label_electric_heater_val = lv_label_create(home_widget.img_ball1);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_val, lv_font_get(60), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_val,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_val,LV_OPA_90,0);
    lv_label_set_text(home_widget.label_electric_heater_val, "50");
    lv_obj_align(home_widget.label_electric_heater_val,LV_ALIGN_CENTER,0,-15);

    home_widget.label_electric_heater_title = lv_label_create(home_widget.img_ball1);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_title, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_title,lv_color_make(0xff,0xff,0xff),0);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_title,LV_OPA_70,0);
    lv_label_set_text(home_widget.label_electric_heater_title, "电热 | °C");
    lv_obj_align(home_widget.label_electric_heater_title,LV_ALIGN_CENTER,0,30);

    // info_ball 2 ***********************************************************************************************************

    home_widget.img_ball2 = lv_img_create(superview);
    lv_img_set_src( home_widget.img_ball2, info_ball[0]);
    lv_obj_set_pos(home_widget.img_ball2,240,54);

    home_widget.label_electric_heater_val = lv_label_create(home_widget.img_ball2);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_val, lv_font_get(60), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_val,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_val,LV_OPA_90,0);
    lv_label_set_text(home_widget.label_electric_heater_val, "40");
    lv_obj_align(home_widget.label_electric_heater_val,LV_ALIGN_CENTER,0,-15);

    home_widget.label_electric_heater_title = lv_label_create(home_widget.img_ball2);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_title, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_title,lv_color_make(0xff,0xff,0xff),0);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_title,LV_OPA_70,0);
    lv_label_set_text(home_widget.label_electric_heater_title, "燃热 | °C");
    lv_obj_align(home_widget.label_electric_heater_title,LV_ALIGN_CENTER,0,30);
}

void ui_home_page_three_dev(lv_obj_t *superview)
{
    // info_ball 1 ***********************************************************************************************************

    home_widget.img_ball1 = lv_img_create(superview);
    lv_img_set_src( home_widget.img_ball1, info_ball[0]);
    lv_obj_set_pos(home_widget.img_ball1,0,20);

    home_widget.label_electric_heater_val = lv_label_create(home_widget.img_ball1);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_val, lv_font_get(60), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_val,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_val,LV_OPA_90,0);
    lv_label_set_text(home_widget.label_electric_heater_val, "50");
    lv_obj_align(home_widget.label_electric_heater_val,LV_ALIGN_CENTER,0,-15);

    home_widget.label_electric_heater_title = lv_label_create(home_widget.img_ball1);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_title, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_title,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_title,LV_OPA_70,0);
    lv_label_set_text(home_widget.label_electric_heater_title, "电热 | °C");
    lv_obj_align(home_widget.label_electric_heater_title,LV_ALIGN_CENTER,0,30);

    // info_ball 2 ***********************************************************************************************************

    home_widget.img_ball2 = lv_img_create(superview);
    lv_img_set_src( home_widget.img_ball2, info_ball[1]);
    lv_obj_set_pos(home_widget.img_ball2,137,93);

    home_widget.label_electric_heater_val = lv_label_create(home_widget.img_ball2);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_val, lv_font_get(28), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_val,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_val,LV_OPA_90,0);
    lv_label_set_text(home_widget.label_electric_heater_val, "已关机");
    lv_obj_align(home_widget.label_electric_heater_val,LV_ALIGN_CENTER,0,-15);

    home_widget.label_electric_heater_title = lv_label_create(home_widget.img_ball2);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_title, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_title,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_title,LV_OPA_70,0);
    lv_label_set_text(home_widget.label_electric_heater_title, "燃热");
    lv_obj_align(home_widget.label_electric_heater_title,LV_ALIGN_CENTER,0,30);

    // info_ball 3 ***********************************************************************************************************

    home_widget.img_ball3 = lv_img_create(superview);
    lv_img_set_src( home_widget.img_ball3, info_ball[0]);
    lv_obj_set_pos(home_widget.img_ball3,270,15);

    home_widget.label_electric_heater_val = lv_label_create(home_widget.img_ball3);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_val, lv_font_get(60), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_val,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_val,LV_OPA_90,0);
    lv_label_set_text(home_widget.label_electric_heater_val, "06");
    lv_obj_align(home_widget.label_electric_heater_val,LV_ALIGN_CENTER,0,-15);

    home_widget.label_electric_heater_title = lv_label_create(home_widget.img_ball3);
    lv_obj_set_style_text_font( home_widget.label_electric_heater_title, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(home_widget.label_electric_heater_title,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(home_widget.label_electric_heater_title,LV_OPA_70,0);
    lv_label_set_text(home_widget.label_electric_heater_title, "净饮 | TDS");
    lv_obj_align(home_widget.label_electric_heater_title,LV_ALIGN_CENTER,0,30);
}


static void home_on_page_create(lv_obj_t* parent,void* ui_data)
{
    debug_d("create\n");
    ui_init_home_page_src(parent);
}
static void home_on_page_destroy(void* ui_data)
{
    debug_d("destroy\n");
    ui_release_home_page_src(NULL);
}
static void home_on_page_update(void* ui_data)
{

}
static page_method_t page_home = {
    .on_page_create  = home_on_page_create,
    .on_page_destroy = home_on_page_destroy,
    .on_page_update  = home_on_page_update,
};

page_method_t* lv_home_page_method(void)
{
    return &page_home;
}